package cn.lili.modules.order.order.entity.dto;


import cn.lili.common.utils.CurrencyUtil;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serial;
import java.io.Serializable;
import java.util.List;

/**
 * 平台营销费用
 *
 * @author liushuai(liushuai711 @ gmail.com)
 * @version v4.0
 * @Description:
 * @since 2023/3/22 11:34
 */
@Builder
@Data
@NoArgsConstructor
@AllArgsConstructor
public class SiteMarketingCost implements Serializable {

    @Serial
    private static final long serialVersionUID = 3915846294212412430L;

    @ApiModelProperty(value = "平台站点营销费用")
    private Double marketingCost;


    @ApiModelProperty(value = "商家承担比例")
    private Integer commitmentPoint;

    @ApiModelProperty(value = "促销备注")
    private String description;

    @ApiModelProperty(value = "营销金额")
    public Double getCommitmentPrice() {

        if (commitmentPoint == null) {
            commitmentPoint = 0;
        }

        if (marketingCost == null || marketingCost == 0) {
            return 0D;
        }

        //假设营销费用100元、店铺承担比例百分之10，那么这里应该是 100 - 100 * 10% 为平台承担费用。即平台应该给店铺90元 = 100*(1-10%)
        //假设营销费用100元、店铺承担比例百分之0，那么这里应该是 100 - 100 * 0 为平台承担费用。即平台应该给店铺100元 = 100*(1-0%)
        //店铺承担金额 = 营销费用 - 营销费用 * 商家承担比例
        return
                CurrencyUtil.sub(marketingCost,
                        CurrencyUtil.div(CurrencyUtil.mul(marketingCost, commitmentPoint), 100));
    }

    /**
     * 统计店铺营销费用
     *
     * @param storeMarketingCosts 营销集合
     * @return 费用
     */
    public static Double countStoreMarketingCost(List<SiteMarketingCost> storeMarketingCosts) {
        Double cost = 0D;
        for (SiteMarketingCost storeMarketingCost : storeMarketingCosts) {
            cost = CurrencyUtil.add(cost, storeMarketingCost.getCommitmentPrice());
        }
        return cost;
    }

}
